<!DOCTYPE html>
  <html>
    <head>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta charset="UTF-8">
     <!--Import Google Icon Font-->
      <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <!-- Compiled and minified CSS -->
	<link rel="stylesheet" href="//cdn.bootcss.com/materialize/0.98.0/css/materialize.min.css">
	<link href="//cdn.bootcss.com/prism/0.0.1/prism.min.css" rel="stylesheet">
	<link rel="shortcut icon" href="/favicon.ico" /> 
	  
	<title>誓言记dovows,那时吹过的牛逼</title>
    </head>

    <body >
	
		<div class="navbar-fixed">
			<nav>
				<div class="nav-wrapper">
				  <a href="http://sinianta.com" class="brand-logo left">誓言记</a>
				  <ul id="nav-mobile" class=" right ">
					
					<li><a href="regist.html">注册</a></li>
					<li><a href="my.html">我的</a></li>
					<li><a href="edithtml.html">页面管理</a></li>
				  </ul>
				</div>
			  </nav>
		  </div>
		  
		  
	<section id="vue-app">
		
		<header>
			<div class="row">
		    <div class="input-field col s6">
		      <input value="my.html" id="filename" type="text" >
		      <label class="active" for="filename">文件名</label>
		    </div>
		  </div>
		</header>
		
		<p >
				<div class="row">
			    <form class="col s12" id="form1" onsubmit="return false;" >
			      <div class="row">
			        <div class="input-field col s12">
			          <textarea id="textarea1" name="data" v-model="html" style="min-height: 300px;" class="materialize-textarea"></textarea>
			          <label for="textarea1">文件内容</label>
			        </div>
			      </div>
			      
			      <button class="btn waves-effect waves-light" type="submit" name="action">提交
					    <i class="material-icons right">send</i>
					  </button>
			    </form>
			  </div>
			  
				
				
			</form>
			
			<pre>
				<code class="language-markup"><a>hi!</a></code>
			</pre>
		</p>
	</section>	
	
	<footer class="page-footer">
          <div class="container">
            <div class="row">
              <div class="col l6 s12">
                <h5 class="white-text">页脚内容</h5>
                <p class="grey-text text-lighten-4">你可以用行和列来组织你的页脚内容。</p>
              </div>
              <div class="col l4 offset-l2 s12">
                <h5 class="white-text">链接</h5>
                <ul>
                  <li><a class="grey-text text-lighten-3" href="#!">链接 1</a></li>
                  <li><a class="grey-text text-lighten-3" href="#!">链接 2</a></li>
                  <li><a class="grey-text text-lighten-3" href="#!">链接 3</a></li>
                  <li><a class="grey-text text-lighten-3" href="#!">链接 4</a></li>
                </ul>
              </div>
            </div>
          </div>
          <div class="footer-copyright">
            <div class="container">
            © 2014 Copyright 文本
            <a class="grey-text text-lighten-4 right" href="#!">更多链接</a>
            </div>
          </div>
        </footer>
	

	  
	  <div class="fixed-action-btn">
	  <!-- Modal Trigger -->
		  <a class="btn-floating btn-large waves-effect waves-light red scrollspy" data-target="modal-1"><i class="material-icons">add</i></a>
	  </div>
	  
	  <div style="display: none;">
	  	<form enctype="multipart/form-data" id="formData">
	  		<input id="_userId" name="_userId"/>
	  		<input id="_token" name="_token"/>
	  		<input id="_ts" name="_ts"/>
	  		<input id="sign" name="sign"/>
	  	</form>
	  </div>
	  
      <!--Import jQuery before materialize.js-->
     <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
      <!-- Compiled and minified JavaScript -->
      <script src="//cdn.bootcss.com/materialize/0.98.0/js/materialize.min.js"></script>
	  <script src="//cdn.bootcss.com/prism/0.0.1/prism.min.js"></script>
	  
	  <script src="//cdn.bootcss.com/vue/2.1.10/vue.min.js"></script>
	  <script src="//cdn.bootcss.com/spark-md5/3.0.0/spark-md5.min.js"></script>
	  <script src="//cdn.bootcss.com/crypto-js/3.1.9/crypto-js.min.js"></script>
	  <script src="js/map-util.js"></script>
	  
	  <script type="text/javascript">
		$(document).ready(function(){
			$.getJSON("config/default.json",function(result){
				console.info(result);
		  });
			
			//加号固定
			$('.scrollspy').scrollSpy();
			
			// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
			$('.modal').modal();
			
			loadDatas('my.html');
			
			
			
		});
		
		function loadDatas(fileName){
			var _userId = "C72E9594F55D1DADFEECFD7A90A82EF6";
			var _token = "D7D8EA7E31E4BC35E10656EDCD38317D";
			var _ts = new Date().getTime();
			
			var formData = new FormData();
			formData.append('_userId', _userId);
			formData.append('_token', _token);
			formData.append('_ts', _ts);
			formData.append('fileName', fileName);
			
			var map = new Map();
			map.put("_userId", _userId);
			map.put("_token", _token);
			map.put("_ts", _ts);
			map.put("fileName", fileName);
			
			var keys = map.keys();
  		var keyArr = keys.sort();
  		
  		console.info(keyArr);
  		
  		var sign = "";
  		var len = keyArr.length;
  		for(var i=0; i < len; i++){
	      var val = map.get(keyArr[i]) + '';
	      if(val.indexOf(',') != -1){
	      	//处理数组的情况，对于参数中以","分割的数组，必须在此排除，后台校验
	          sign += val.split(',').join('');
	      }else{
	          sign += val;  
	      }
		  }
  		
  		var signKey = "renkegfhfgdst45dsdf3";//应该由服务器结合用户编号MD5生成
  		sign += signKey;
  		console.info(sign);
  		
  		sign = CryptoJS.MD5(sign,'utf-8').toString();
			console.info(sign);
			
			formData.append('_sign', sign);
			var jqxhr = $.ajax({
				  url: "/api/he-sys/read$code2str",
				  method: "POST",
				  data: formData,
				  dataType: "json",
				  processData: false,  // 告诉jQuery不要去处理发送的数据
  				contentType: false   // 告诉jQuery不要去设置Content-Type请求头
			}).done(function( msg ) {
		    console.info(msg)
				Materialize.toast(msg.data, 4000);
				app.html = msg.data;
		  }).fail(function(msg) {
		  	console.info(msg)
		    Materialize.toast("error", 4000); 
		  })
		  .always(function(msg) {
		    Materialize.toast(msg.message, 4000)
		  });
			
		}
		
		var app = new Vue({
		  el: '#vue-app',
		  data: {
				items:[],
				html: '',
		  },
		  methods: {
			commitVows: function (event) {
			  var params = $("#form-vow").serialize();
			  params += "&t=vow";
			  params += "&isLive=1";
			  $.ajax({
				  url: "/api/base/s$",
				  method: "POST",
				  data: params,
				  dataType: "json",
				  success: function(msg){
					  Materialize.toast('你已发出誓言，记得完成目标哦', 4000); // 4000 is the duration of the toast
					  getVows();
				  }
				
			  });
			}
		  }
  
		})
		
		//根据文件名获取内容
		$("#filename").on('change', function(){
			loadDatas(this.value);
		});
		
		$("#form1").on('submit', function(){
			var _userId = "C72E9594F55D1DADFEECFD7A90A82EF6";
			var _token = "D7D8EA7E31E4BC35E10656EDCD38317D";
			var _ts = new Date().getTime();
			var fileName = $("#filename").val();
			
			var formData = new FormData(this);
			formData.append('_userId', _userId);
			formData.append('_token', _token);
			formData.append('_ts', _ts);
			formData.append('fileName', fileName);
			
			var map = new Map();
			map.put("_userId", _userId);
			map.put("_token", _token);
			map.put("_ts", _ts);
			map.put("fileName", fileName);
			map.put("data", formData.get('data'));
			
			var keys = map.keys();
  		var keyArr = keys.sort();
  		
  		console.info(keyArr);
  		
  		var sign = "";
  		var len = keyArr.length;
  		for(var i=0; i < len; i++){
	      var val = map.get(keyArr[i]) + '';
	      if(val.indexOf(',') != -1){
	      	//处理数组的情况，对于参数中以","分割的数组，必须在此排除，后台校验
	          sign += val.split(',').join('');
	      }else{
	          sign += val;  
	      }
		  }
  		
  		var signKey = "renkehgfd54354fdsfd333";//应该由服务器结合用户编号MD5生成
  		sign += signKey;
  		console.info(sign);
  		
  		sign = CryptoJS.MD5(sign,'utf-8').toString();
			console.info(sign);
			
			formData.append('_sign', sign);
			
			var jqxhr = $.ajax({
				  url: "/api/he-sys/deploy$code",
				  method: "POST",
				  data: formData,
				  dataType: "json",
				  processData: false,  // 告诉jQuery不要去处理发送的数据
  				contentType: false   // 告诉jQuery不要去设置Content-Type请求头
			}).done(function( msg ) {
		    console.info(msg)
				Materialize.toast(msg.data, 4000);
		  }).fail(function(msg) {
		  	console.info(msg)
		    Materialize.toast("error", 4000); 
		  })
		  .always(function(msg) {
		    Materialize.toast(msg.message, 4000)
		  });
		});
		
	  </script>
    </body>
  </html>
        